<?php
namespace shenka\controllers;

use Yii;
use yii\web\Controller;
use shenka\models\User;
use shenka\models\UserLogin;
use shenka\controllers\classes\QueryClass;

/*
* @author admin 
* @class Common
* @desc 星球大冒险（中）& 美术棒注册登录统计
*/
class CommonController extends Controller {
	
	/*
	* @author admin 
	* @function Dreg
	* @desc 日注册量
	*/
	public function actionDreg(){
		$view = Yii::$app->view;
		$view->params['layout_data'] = '星球大冒险（中）&美术棒';

		// 日注册量
		$reg = QueryClass::dataJson('register_time','%Y-%m-%d','sys_user',[],15);

		$sum = User::find()->count('id');
		// 周注册量
		$wreg = QueryClass::weekJson('register_time','%Y-%u','sys_user',7);
		// 月注册量 
		$mreg = QueryClass::dataJson('register_time','%Y-%m','sys_user',[],6);
		$msum = User::find()->count();
		// 各时段注册量
		$model = new User();
		if($model->load(Yii::$app->request->post()) == null) {
			$time = date('Y-m-d',time());
		}else{
			$time = $_POST['User']['register_time'];
		}
		
		return $this->render('dreg',['reg'=>$reg,'sum'=>$sum,'type'=>'星球大冒险','wreg'=>$wreg,'mreg'=>$mreg,'msum'=>$msum]);

	}
	/*
	* @author admin 
	* @function Wreg
	* @desc 周注册量
	*/
	public function actionWreg(){
		
	}
	/*
	* @author admin 
	* @function Mreg
	* @desc 月注册量 
	*/
	public function actionMreg(){
		
	}
	/*
	* @author admin 
	* @function Hreg
	* @desc 各时段注册量
	*/
	public function actionHreg(){

		$model = new User();

		if(Yii::$app->request->isAjax){			
			$time = !empty($_POST["time"]) ? $_POST["time"] : date('Y-m-d',time());
		}else{
			$time = date('Y-m-d',time());
		}
		// var_dump($time);
		
		$reg = QueryClass::_getHoursData($model,'register_time',$time);
		
		return $reg;

	}


	/*
	* @author admin 
	* @function Dlog
	* @desc 日活跃量
	*/
	public function actionDlog(){
		$view = Yii::$app->view;
		$view->params['layout_data'] = '星球大冒险（中）&美术棒';
		// 日活跃量
		$log = QueryClass::dataJson('create_time','%Y-%m-%d','sys_user_log_login',[],15);
		$sum = UserLogin::find()->count();
		// 周活跃量
		$wlog = QueryClass::weekJson('create_time','%Y-%u','sys_user_log_login',7);
		
		//月活跃量
		$mlog = QueryClass::dataJson('create_time','%Y-%m','sys_user_log_login',[],6);
		//$msum = UserLogin::find()->count();
		//各时段活跃量
		$model = new UserLogin();
		if($model->load(Yii::$app->request->post()) == null){
			$time = date('Y-m-d',time());
		}else{
			$time = $_POST['UserLogin']['create_time'];
		}
		
		$hlog = QueryClass::_getHoursData($model,'create_time',$time);
		return $this->render('dlog',['log'=>$log,'wlog'=>$wlog,'mlog'=>$mlog,'msum'=>$sum,'model'=>$model,'hlog'=>$hlog,'time'=>$time]);
	}
	/*
	* @author admin 
	* @function Wlog
	* @desc 周活跃量 
	*/
	public function actionWlog(){
	
	}
	/*
	* @author admin 
	* @function Mlog
	* @desc 月活跃量
	*/
	public function actionMlog(){
	
	}
	/*
	* @author admin 
	* @function Hlog
	* @desc 各时段活跃量
	*/
	public function actionHlog(){
		$model = new UserLogin();
		if(Yii::$app->request->isAjax){
			$time = !empty($_POST["time"]) ? $_POST["time"] : date('Y-m-d',time());
		}else {
			$time = date('Y-m-d',time());
		}
		$log = QueryClass::_getHoursData($model,'create_time',$time);

		return $log;
	}
}